import { fetchLoginList, fetchBehaviorList, fetchRequestList, fetchTaskList, fetchQueueList } from './api'

export default {
  namespaced: true,
  state: () => ({
    login_list: [],
    login_total: 0,
    behavior_list: [],
    behavior_total: 0,
    request_list: [],
    request_total: 0,
    task_list: [],
    task_total: 0,
    queue_list: [],
    queue_total: 0
  }),
  getters: {
    login_list (state) {
      return state.login_list
    },
    login_total (state) {
      return state.login_total
    },
    behavior_list (state) {
      return state.behavior_list
    },
    behavior_total (state) {
      return state.behavior_total
    },
    request_list (state) {
      return state.request_list
    },
    request_total (state) {
      return state.request_total
    },
    task_list (state) {
      return state.task_list
    },
    task_total (state) {
      return state.task_total
    },
    queue_list (state) {
      return state.queue_list
    },
    queue_total (state) {
      return state.queue_total
    }
  },
  actions: {
    async fetchLoginList ({ commit }, params) {
      const { data } = await fetchLoginList(params)
      commit('SET_LOGIN_LIST', data)
    },
    async fetchBehaviorList ({ commit }, params) {
      const { data } = await fetchBehaviorList(params)
      commit('SET_BEHAVIOR_LIST', data)
    },
    async fetchRequestList ({ commit }, params) {
      const { data } = await fetchRequestList(params)
      commit('SET_REQUEST_LIST', data)
    },
    async fetchTaskList ({ commit }, params) {
      const { data } = await fetchTaskList(params)
      commit('SET_TASK_LIST', data)
    },
    async fetchQueueList ({ commit }, params) {
      const { data } = await fetchQueueList(params)
      commit('SET_QUEUE_LIST', data)
    }
  },
  mutations: {
    SET_LOGIN_LIST (state, payload) {
      state.login_list = payload.data
      state.login_total = payload.meta.total
    },
    SET_BEHAVIOR_LIST (state, payload) {
      state.behavior_list = payload.data
      state.behavior_total = payload.meta.total
    },
    SET_REQUEST_LIST (state, payload) {
      state.request_list = payload.data
      state.request_total = payload.meta.total
    },
    SET_TASK_LIST (state, payload) {
      state.task_list = payload.data
      state.task_total = payload.meta.total
    },
    SET_QUEUE_LIST (state, payload) {
      state.queue_list = payload.data
      state.queue_total = payload.meta.total
    }
  }
}
